const app = getApp(),
  $extConfig = xhs.getExtConfigSync(),
  $config = require("../../config.js"),
  $resHost = $extConfig.resHost || $config.resHost;
Component({
  /**
   * 组件的属性列表a
   */
  properties: {
    isOpenPhone: {
      //主动触发手机授权
      type: Boolean,
      value: false
    }
  },
  attached() {
    if (xhs.getPrivacySetting) {
      xhs.getPrivacySetting({
        success: res => {
          if (res.needAuthorization) {
            this.setData({
              needAuthorization: true,
              privacyContractName: res.privacyContractName
            });
          } else {
            this.triggerEvent("agree");
          }
        },
        fail: () => {},
        complete: () => {}
      });
    } else {
      // 低版本基础库不支持 wx.getPrivacySetting 接口，隐私接口可以直接调用
      this.triggerEvent("agree");
    }
    app.$getConfigData();
  },
  data: {
    wechatInfo: {},
    defImg: `${$resHost}/img/def.jpg`,
    isShow: true,
    needAuthorization: false,
    //用户隐私协议
    privacyContractName: "" //隐私协议的名称
  },
  /**
   * 组件的方法列表
   */
  methods: {
    closeSq() {
      this.setData({
        isShow: false
      });
      this.triggerEvent("disagreeP");
    },
    openPrivacyContract() {
      xhs.openPrivacyContract({
        success: res => {
          console.log("openPrivacyContract success");
        },
        fail: res => {
          console.error("openPrivacyContract fail", res);
        }
      });
    },
    handleAgreePrivacyAuthorization() {
      this.setData({
        needAuthorization: false
        // },()=>{
        //   this.getUserInfo()
      });
      this.triggerEvent("agreeP");
      this.triggerEvent("formagreeP");
    }
  }
});